package com.china08.yxyapi.api.home.weikecheng;

import java.lang.reflect.InvocationTargetException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.user.YxyUserCenter;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.service.mg.YxyUserCenterService;

@CrossOrigin
@RestController
public class WeikeRecordContentController extends YxyApiBaseController {

    @Autowired
    private YxyUserCenterService userCenterService;

    @ResponseBody
    @RequestMapping(value = "/api_yw/home/weike/content/record", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel process(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel)
            throws IllegalAccessException, InvocationTargetException {
        String userId = getProfile(request, response).getId();
        if (StringUtils.isNotBlank(userId)) {
            YxyUserCenter center = userCenterService.getYxUserCenter(userId);
            userCenterService.updYxUserCenterWeikeContent(center, reqModel.phase, reqModel.subject, reqModel.version,
                    reqModel.subjectName, reqModel.phaseName, reqModel.versionName, reqModel.bookId, reqModel.semester,
                    reqModel.semesterName);
        }
        RespModel model = new RespModel();
        model.setMessage("成功");
        return model;
    }

    protected static class ReqModel extends YxyApiRespModel {
        public String phase;
        public String phaseName;
        public String subject;
        public String subjectName;
        public String version;
        public String versionName;
        public String bookId;
        public String semester;
        public String semesterName;

    }

    public static class RespModel extends YxyApiRespModel {

    }

}
